package nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Test12 {

    public static void main(String[] args) throws IOException {

        RandomAccessFile file = new RandomAccessFile("blahblah.txt","rw");

        FileChannel channel = file.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        int bytes = channel.read(buffer);

        while (bytes != -1) {

            System.out.println("bytes:"+bytes);


            buffer.flip();
            while (buffer.hasRemaining()) {
                System.out.print((char) buffer.get());
            }

            buffer.clear();

            bytes = channel.read(buffer);

        }

    }

}
